<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<link rel="stylesheet" href="../css/iconfont.css" />
		<script src="../js/head_public.js"></script>
		<style>
			.mui-active{color: #ff7e00!important;}
			.sp-con h1{overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
			.del{position: absolute;top: 5px;right: 5px;width: 15px;}
			
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav ding-bar">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">购物车</h1>
		</header>
		<div class="mui-content">
		    <!--<div class="gwc-adress-container">
		    	<!--<h1 class="mui-navigate-right">收货地址<img src="../images/mdate_right.png" style="float: right;width: 0.5rem;"></h1>
		    	<p class="person-icon"><span>收货人：王潇潇</span><span>18193186350</span></p>
		    	<p class="ads-icon">地址：甘肃省兰州市七里河区西湖公园甘肃省兰州市七里河区西湖公园</p>-->
		    <!--</div>-->
		    <ul class="car-list">
		    	<!--<li>
		    		<div class="chose-icon" ischoosed="0">
		    			<img  src="../images/gwc-img3.png"/>
		    		</div>
		    		<div class="sp-icon">
		    			<img src="../images/gwc-img5.png" />
		    		</div>
		    		<div class="sp-con">
		    			<h1>彩色童袜</h1>
		    			<p class="sku">6-14岁</p>
		    			<p class="car-price">￥<span class="jiage">5</span>/积分<span class="jifen">19.9</span></p>
		    		</div>
		    		<ul class="gwc-num">
		    			<li class="jian">-</li>
		    			<li class="num-con">1</li>
		    			<li class="jia">+</li>
		    		</ul>
		    	</li>
		    	<li>
		    		<div class="chose-icon"ischoosed="0">
		    			<img  src="../images/gwc-img3.png"/>
		    		</div>
		    		<div class="sp-icon">
		    			<img src="../images/gwc-img5.png" />
		    		</div>
		    		<div class="sp-con">
		    			<h1>彩色童袜</h1>
		    			<p class="sku">6-14岁</p>
		    			<p class="car-price">￥<span class="jiage">5</span>/积分<span class="jifen">19.9</span></p>
		    		</div>
		    		<ul class="gwc-num">
		    			<li class="jian">-</li>
		    			<li class="num-con">1</li>
		    			<li class="jia">+</li>
		    		</ul>
		    	</li>
		    	<li>
		    		<div class="chose-icon" ischoosed="0">
		    			<img  src="../images/gwc-img3.png"/>
		    		</div>
		    		<div class="sp-icon">
		    			<img src="../images/gwc-img5.png" />
		    		</div>
		    		<div class="sp-con">
		    			<h1>彩色童袜</h1>
		    			<p class="sku">6-14岁</p>
		    			<p class="car-price">￥<span class="jiage">5</span>/积分<span class="jifen">19.9</span></p>
		    		</div>
		    		<ul class="gwc-num">
		    			<li class="jian">-</li>
		    			<li class="num-con">1</li>
		    			<li class="jia">+</li>
		    		</ul>
		    	</li>-->
		    </ul>
		    <div class="gwc-footer">
		    	<div class="quanxuan" flag="0">
		    		<img src="../images/gwc-img3.png" />
		    		<span>全选</span>
		    	</div>
		    	<div class="heji">
		    		合计：<span id="jiage">0</span>元/<span id="jifen">0</span>积分
		    	</div>
		    	<div class="jiesuan">
		    		<img src="../images/jiesuan.png" />
		    	</div>
		    </div>
		</div>
		<footer>
			<nav class="mui-bar mui-bar-tab gouwu-footer">
				<a class="mui-tab-item " data-href="../public/index.html">
					<span class="mui-icon  iconfont icon-shangcheng "></span>
					<span class="mui-tab-label">首页</span>
				</a>
				<a class="mui-tab-item " data-href="car.html">
					<span class="mui-icon iconfont icon-gouwuche sp-footer-active"></span>
					<span class="mui-tab-label sp-footer-active">购物车</span>
				</a>
				<a class="mui-tab-item" data-href="wode.html">
					<span class="mui-icon iconfont icon-Personal"></span>
					<span class="mui-tab-label">我的</span>
				</a>
			</nav>
		</footer>
		<script src="../js/mui.min.js"></script>
		<script src="../js/jquery-1.8.0.min.js"></script>
		<script src="../js/common.js"></script>
		<script src="../js/session.js"></script>
		<script>
			
//			$("footer").load("footer2.html")
		</script>
		<script type="text/javascript">
			mui.init()
			mui(".mui-content").on("tap","a",function(){
				mui.openWindow({url:$(this).attr("data-href")})
			})
			mui("footer").on("tap","a",function(){
				location.href=$(this).attr("data-href");
//				mui.openWindow({url:$(this).attr("data-href")})
			})

//           点击选择
            $(".car-list").on("tap",".chose-icon",function(){
            	if($(this).attr("ischoosed")=="0"){
            		$(this).attr("ischoosed","1");
            		$(this).find("img").attr("src","../images/gwc-img4.png");
            	}else{
            		$(this).attr("ischoosed","0");
            		$(this).find("img").attr("src","../images/gwc-img3.png");
            	}
            	changeAll()
            	$("#jiage").html(total());
            	$("#jifen").html(total_jifen());
            })
//          判断是否全选
            function isAll(){
            	
            	var isall=true;
            	 $(".chose-icon").each(function(i){
	             	if($(this).attr("ischoosed")=="0"){
	             		isall=false;
	             	}
	             	
	             })
            	 
            	 return isall;
            }
//          改变全选的样式
            function changeAll(){
            	
            	if(isAll()){
            		$(".quanxuan").find("img").attr("src","../images/gwc-img4.png");
            	}else{
            		$(".quanxuan").find("img").attr("src","../images/gwc-img3.png");
            	}
            }
//          点击全选全部商品都选中
            mui(".gwc-footer").on("tap",".quanxuan",function(){
            	if($(this).attr("flag")=="0"){
            		$(this).attr("flag","1");
            		$(".quanxuan").find("img").attr("src","../images/gwc-img4.png");
                    $(".chose-icon").each(function(i){
		             	$(this).attr("ischoosed","1");
	             	    $(this).find("img").attr("src","../images/gwc-img4.png");
	                })
            	}else{
            		$(this).attr("flag","0");
            		$(".quanxuan").find("img").attr("src","../images/gwc-img3.png");
                    $(".chose-icon").each(function(i){
		             	$(this).attr("ischoosed","0");
	             	    $(this).find("img").attr("src","../images/gwc-img3.png");
	                })
            	}
            	 $("#jiage").html(total());
             	 $("#jifen").html(total_jifen());
            })
//          合计价格
            function total(){
            	var sum=0;
            	$(".car-list li").each(function(i){
            		var s=0;
            		if($(this).find(".chose-icon").attr("ischoosed")=="1"){
            			s=parseFloat($(this).find(".jiage").html())*parseInt($(this).find(".num-con").html());
            		    sum+=s;
            		}
            	})
            	sum = Math.round(sum*100)/100;
            	return sum;
            }
//          合计总积分
            function total_jifen(){
            	var sum=0;
            	$(".car-list li").each(function(i){
            		var s=0;
            		if($(this).find(".chose-icon").attr("ischoosed")=="1"){
            			s=parseFloat($(this).find(".jifen").html())*parseInt($(this).find(".num-con").html());
            		    sum+=s;
            		}
            	})
            	sum = Math.round(sum*100)/100;
            	return sum;
            }
            //判断是否登录
            var userid=getCookie("userid")
            if(userid==""||userid==null){
             		alert("您还没有登录，请先登录")
             		location.href="../public/login.html"
            }else{
             		$.post(net+"/public/index.php?s=api/cart/index",{"member_id":userid},function(res){
             			if(res.code=="200"){
             				if(res.result!=null&&res.result.length!=0){
             					var str="";
             					$.each(res.result, function(index,val) {
             						var oranial_price="";
             						if(this.is_discount==1){
             							oranial_price='<span style="color:#999999;font-size:12px;text-decoration:line-through;position: absolute;top: 66px;right: 5px;">￥'+this.oranial_price+'</span>'
             						}
             						var src=net+"public/uploads/home/store/goods/"+this.store_id+"/"+this.goods_image;
             						str+='<li data-id="'+this.cart_id+'" class="carli" style="position:relative"><div class="chose-icon"ischoosed="0"><img  src="../images/gwc-img3.png"/></div>'
		    		                   +'<div class="sp-icon"><img src="'+src+'" /></div>'
		    			               +'<div class="sp-con"><h1>'+this.goods_name+'</h1><ul class="gwc-num1"><li class="jian">-</li><li class="num-con">'+this.goods_num+'</li><li class="jia">+</li></ul><p class="car-price" >￥<span class="jiage">'+this.goods_price+'</span>/积分<span class="jifen">'+this.goods_point+'</span></p>'+oranial_price+'</div>'
		    		                   +'<img src="../images/close.png" class="del" data-id="'+this.cart_id+'"></li>'
		    			    	
             					});
             					$(".car-list").append(str);
             				}
             			}
             		})
//                  //读取收获地址
//           		$.post(net+"/public/index.php?s=api/Cart/address/",{"member_id":userid},function(res){
//           			if(res.code=="200"){
//           				if(res.result!=null&&res.result.length!=0){
//           					var str="";
//           					var src=net+"public/uploads/home/store/goods/"+this.store_id+"/"+this.goods_image;
//           					str='<h1 >收货地址<img src="../images/mdate_right.png" style="float: right;width: 0.5rem;"id="go-list"></h1><p class="person-icon"><span>收货人：'+res.result.address_realname+'</span><span style="margin-left:5px">'+res.result.address_mob_phone+'</span></p><p class="ads-icon">地址：'+res.result.address_detail+'</p> '
//           					$(".gwc-adress-container").append(str);
//           				}
//           				mui(".gwc-adress-container").on("tap","#go-list",function(){
//           					mui.openWindow({url:"address.html"})
//           				})
//           			}
//           		})
             		//			购物车加减
           
	             mui(".car-list").on("tap",".jia",function(){
	             	var car_id=$(this).parents(".carli").attr("data-id")
	             	var num=parseInt($(this).siblings(".num-con").html());
	             	var $this=$(this);
	             	if(num!=null&&num!=""){
	             	 	num++;
	             	 	var paramsnum={};
	             	 	paramsnum.member_id=userid;
	             	 	paramsnum.cart_id=car_id;
	             	 	paramsnum.quantity=num;
	             	 	$this.siblings(".num-con").html(num);
	             	 	$.post(net+"/public/index.php?s=api/Cart/update/",paramsnum,function(res){
	             	 	    if(res.code=="200"){
	             	 	   	    $this.siblings(".num-con").html(res.result.goods_num);
	             	 	    }
	             	 	})
	             	 	$("#jiage").html(total());
	             	 	$("#jifen").html(total_jifen());
	           	    }
	             })
	             mui(".car-list").on("tap",".jian",function(){
	             	var car_id=$(this).parents(".carli").attr("data-id")
	             	var num=parseInt($(this).siblings(".num-con").html());
	             	var $this=$(this);
	             	 if(num!=null&&num!=""){
	             	 	if(num<=1){
	             	 		alert("已经最小了，不能再减了")
	             	 		num=1;
	             	 	    var paramsnum={};
		             	 	paramsnum.member_id=userid;
		             	 	paramsnum.cart_id=car_id;
		             	 	paramsnum.quantity=num;
		             	 	$.post(net+"/public/index.php?s=api/Cart/update/",paramsnum,function(res){
		             	 	   if(res.code=="200"){
		             	 	   	    $this.siblings(".num-con").html(res.result.goods_num);
		             	 	    }
		             	 	})
//	             	 		$(this).siblings(".num-con").html(num);
	             	 		$("#jiage").html(total());
	             	 		$("#jifen").html(total_jifen());
	             	 	}else{
	             	 		num--;
	             	 	    var paramsnum={};
		             	 	paramsnum.member_id=userid;
		             	 	paramsnum.cart_id=car_id;
		             	 	paramsnum.quantity=num;
		             	 	$this.siblings(".num-con").html(num);
		             	 	$.post(net+"/public/index.php?s=api/Cart/update/",paramsnum,function(res){
		             	 	   if(res.code=="200"){
		             	 	   	    $this.siblings(".num-con").html(res.result.goods_num);
		             	 	    }
		             	 	})
	             	 	    $("#jiage").html(total());
	             	 	    $("#jifen").html(total_jifen());
	             	 	}
	             	 	
	             	 }
	             })	
	             //删除
	              mui(".car-list").on("tap",".del",function(){
	              	 var cart_id=$(this).attr("data-id");
	              	 var data1={};
	              	 data1.cart_id=cart_id;
	              	 data1.member_id=userid;
	              	 $.post(net+"/public/index.php?s=api/Cart/del",data1,function(res){
	              	 	if(res.code=="200"){
	              	 		location.reload();
	              	 	}
	              	 })
	              })
	             //点击结算生成订单
	              mui(".gwc-footer").on("tap",".jiesuan",function(){
	              	var str="";
	              	//循环取的商品id与数量
	              	 $(".car-list li").each(function(index){
	              	 	if($(this).find(".chose-icon").attr("ischoosed")=="1"){
	              	 		var good_id=$(this).attr("data-id");
	              	 		var goodnum=$(this).find(".num-con").html();
	              	 		str+=good_id+"_"+goodnum+","
	              	 	}
	              	})
	              	    var reg=/,$/gi;
                        str=str.replace(reg,"");//截去字符串最后的逗号
                        var d_param={};
                        if(str==""){
                        	alert("您还没有选择您所需要的商品");
                        	return false;
                        }
                        d_param.member_id=userid;
                        d_param.cart=str;
                        d_param.ifcart="1";
                        //请求接口
	              	 $.post(net+"/public/index.php?s=api/buy/buy_step1",d_param,function(res){
	              	 	if(res.code=="200"){
	              	 		if(res.result!=null){
	              	 			addCookie("res",JSON.stringify(res))
	              	 			mui.openWindow({
	              	 				url:"pay.html?ye=1"
	              	 			})
	              	 		}
	              	 	}
	              	 })
	              }) 		
             }
       
		</script>
	</body>

</html>